<template>
  <el-container>
    <el-aside width="200px">
      <el-menu>
        <el-submenu index="1" v-if="data.user.role === 1">
          <template #title><i class="el-icon-message"></i>编辑资讯管理</template>
          <el-menu-item index="1-1">
            <router-link to="/new/article">编辑新资讯</router-link>
          </el-menu-item>

          <el-menu-item index="1-2">
            <router-link to="/list/1">等待审核资讯</router-link>
          </el-menu-item>

          <el-menu-item index="1-3">
            <router-link to="/list/2">审核未通过资讯</router-link>
          </el-menu-item>

          <el-menu-item index="1-4">
              <router-link to="/list/4">已发布资讯</router-link>
          </el-menu-item>
        </el-submenu>

        <el-submenu index="2" v-else-if="data.user.role === 2">
          <template #title><i class="el-icon-menu"></i>审核资讯管理</template>
          <el-menu-item index="2-1">
            <router-link to="/list/1">等待审核资讯</router-link>
          </el-menu-item>
          <el-menu-item index="2-2">
            <router-link to="/list/3">等待发布资讯</router-link>
          </el-menu-item>
          <el-menu-item index="2-3">
            <router-link to="/list/4">已发布资讯</router-link>
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <span>{{data.user.username}}</span>
        <el-dropdown>
          <i class="el-icon-setting" style="margin: 0 15px"></i>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>个人信息</el-dropdown-item>
              <el-dropdown-item @click="layout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </el-header>

      <el-main>
        <router-view :key="$route.fullPath"/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import {reactive} from "vue";

export default {
  name: "Main",
  setup() {
    const  data = reactive({
      user: JSON.parse(window.sessionStorage.getItem('user'))
    })

    const layout = ()=>{
      window.sessionStorage.removeItem('user');
      window.location.reload();
    }

    const reload = ()=>{
      this.isRouterView = false;
      this.$nextTick(function () {
        this.isRouterView = true;
      })
    }


    return{
      data,
      layout,
      reload
    }
  }
};
</script>

<style>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}

a {
  text-decoration: none;
}
</style>
